<template>
	<view class="cjxx-content tn-padding">
		<view class="view-item tn-margin-bottom-sm si-view-item">
				<view class="tn-float-left tn-padding-right left-view tn-text-center">
					<!-- <text class="tn-color-red tn-padding-right-sm">*</text> -->
					<text>姓名</text>
				</view>
				<view class="tn-float-left right-view search-view" v-if="detailId || !isTooday">
					<text>{{youerName}}</text>
				</view>
				<view class="tn-float-left right-view search-view" v-else>
					<tn-input class="mingc-inp" v-model="youerName" placeholder="请输入姓名" @input="inputchange" type="text" :height="60" :border="true" />
					<view class="search-re-view" v-if="searchNames.length">
						<view class="names-item" v-for="(item, index) in searchNames" :key="index" @click="chooseNames(item)">
							{{item.showLable}}
						</view>
					</view>
				</view>
		</view>
		<view v-if="youerDetail.id" class="view-item tn-margin-bottom-sm">
				<view class="tn-float-left tn-padding-right left-view tn-text-center">
					<text>班级</text>
				</view>
				<view class="tn-float-left right-view">
					{{youerDetail.className}}
				</view>
		</view>
		<view v-if="youerDetail.id" class="view-item tn-margin-bottom-sm">
				<view class="tn-float-left tn-padding-right left-view tn-text-center">
					<text>年龄</text>
				</view>
				<view class="tn-float-left right-view">
					{{youerDetail.age}}
				</view>
		</view>
		<view v-if="youerDetail.id" class="view-item tn-margin-bottom-sm">
				<view class="tn-float-left tn-padding-right left-view tn-text-center">
					<text>体温</text>
				</view>
				<view class="tn-float-left right-view">
					<tn-input class="tiwen-inp" v-model="tiwendushu" placeholder="请输入温度" type="text" :height="60" :border="true" />
					<text class="du-text">度</text>
				</view>
		</view>
		
		<view v-if="youerDetail.id" class="view-item tn-margin-bottom-sm">
				<view class="tn-float-left tn-padding-right left-view tn-text-center">
					<!-- <text class="tn-color-red tn-padding-right-sm">*</text> -->
					<text>咽喉</text>
				</view>
				<view class="tn-float-left right-view">
					<view class="yanhou-zz bg-zhencheng" :class="[activeIndex == 1?'bg-active':'']" @click="activeIndex = 1">
						正常
						<text v-if="activeIndex == 1?true:false" class="tn-icon-success"></text>
					</view>
					<view class="yanhou-zz bg-qingwei" :class="[activeIndex == 2?'bg-active':'']" @click="activeIndex = 2">
						轻微
						<text v-if="activeIndex == 2?true:false" class="tn-icon-success"></text>
					</view>
					<view class="yanhou-zz bg-yanzhong" :class="[activeIndex == 3?'bg-active':'']" @click="activeIndex = 3">
						严重
						<text v-if="activeIndex == 3?true:false" class="tn-icon-success"></text>
					</view>
				</view>
		</view>
		<view v-if="youerDetail.id && isTooday" class="tn-padding-sm canvas-view">
			<tn-button  width="100%" backgroundColor="#79CF67" fontColor="#fff" @click="submitjilu">提交</tn-button>
		</view>
		<view class="noyouer-view" v-if="youerName && !youerDetail.id">
			查无此人
		</view>
		
		<tn-toast
		  ref="toast"
		></tn-toast>
	</view>
</template>

<script>
	export default {
		name: 'chenjiandengji',
		
		data(){
			return {
				youerName: '',
				activeIndex: 1,
				tiwendushu: '',
				searchNames: [],
				youerDetail: {},
				detailId: '',
				isTooday: true,
				recordTime: ''
			}
		},
		onLoad:function(options){
		    console.log(options.name, options.id); 
			
			if(options.id && options.id !== 'null'){
				this.detailId = options.id
				this.getDetailInfo()
			}else{
				if(options.name){
					this.youerName = options.name
					this.searchNamesFunction(true)
				}
			}
			if(options.recordTime){
				this.bijiaoriqi(options.recordTime)
			}
		},
		onShow() {
		},
		mounted() {
			
		},
		methods:{
			bijiaoriqi(recordTime){
				var dd = new Date()
				let y = dd.getFullYear();
			　　let m = dd.getMonth() + 1 < 10 ? "0" + (dd.getMonth() + 1) : dd.getMonth() + 1;
			　　let d = dd.getDate() < 10 ? "0" + dd.getDate() : dd.getDate();
				let dangqianriqi = y+'-'+m+'-'+d;
				console.log(dangqianriqi, recordTime)
				if(dangqianriqi !== recordTime){
					this.isTooday = false
				}
			},	
			clear(){},
			shoudong(){
				
			},
			getDetailInfo(){
				this.request({
					url: '/MCheck/Get',
					method: 'get',
					params: {
						Id: this.detailId,
					},
				}).then(res => {
					if(res.code == 200){
						this.youerDetail = {
							id: res.data.childrenId,
							className: res.data.className,
							age: res.data.age,
						}
						this.tiwendushu = res.data.bodyTemperature
						this.youerName = res.data.childrenName
						this.activeIndex = res.data.throatType
					}
				})
			},
			submitjilu(){
				if(!this.tiwendushu){
						this.$refs.toast.show({
							title: '',
							content: '请输入幼儿体温',
							icon: 'tips',
							image: '',
							duration: 1500
						})	
					return
				}
				let postObj = {
					ChildrenId: this.youerDetail.id,
					BodyTemperature: this.tiwendushu,
					ThroatType: this.activeIndex
				}
				let url = '/MCheck/Add';
				if(this.detailId){
						url = '/MCheck/Edit';
						postObj.id = this.detailId
				}
				this.request({
					url: url,
					method: 'post',
					params: postObj
				}).then(res => {
					if(res.code == 200){
						this.$refs.toast.show({
							title: '',
							content: '提交成功',
							icon: 'success',
							image: '',
							duration: 1500
						})		  
					}else{
						this.$refs.toast.show({
							title: '',
							content: res.message,
							icon: 'fail',
							image: '',
							duration: 1500
						})
					}
				})
			},
			inputchange(val){
				this.searchNames = [];
				if(!val){
					this.youerName = '';
					this.youerDetail = {};
					return
				}
				
				this.searchNamesFunction()
			},
			chooseNames(item){
				this.youerName = item.name;
				this.youerDetail = item;
				this.searchNames = []
				this.tiwendushu = ''
						console.log(this.youerDetail, this.isTooday)
			},
			searchNamesFunction(isAdd){
				this.searchNames = []
				this.request({
					url: '/Children/page',
					method: 'get',
					params: {
						ChildName: this.youerName,
						PageNo: 1,
						PageSize: 10
					},
				}).then(res => {
					if(res.code == 200 && res.data.rows){
						this.searchNames = res.data.rows.map(item => {
							item.showLable = item.className + '-' + item.name
							return item
						})
						if(isAdd && this.searchNames.length == 1){
							this.chooseNames(this.searchNames[0])
						}
					}
				})
			}
		}
	}
</script>

<style lang="scss" scoped>
	.cjxx-content{
		min-height: 100vh;
		background-color: rgba(255, 255, 255, 1);
	}
	
	.view-item{
		min-height: 70rpx;
		line-height: 70rpx;
		overflow: hidden;
	}
	
	.right-view{
		width: calc(100% - 200rpx);
	}
	.left-view{
		width: 200rpx;
	}
	.tiwen-inp{
		width: calc(100% - 100rpx);
		float: left;
		background-color: #ffffff;
	}
	.du-text{
		display: inline-block;
		width: 100rpx;
		text-align: center;
	}
	.yanhou-zz{
		width: 80%;
		text-align: center;
		color: #ffffff;
		margin-bottom: 30rpx;
		line-height: 50rpx;
		margin-left: 4%;
	}

	.bg-zhencheng{
		background-color: #A4E82F;
	}
	.bg-qingwei{
		background-color: #FFCA28;
	}
	.bg-yanzhong{
		background-color: #D9001B;
	}
	.color-zhencheng{
		color: #A4E82F;
	}
	.color-qingwei{
		color: #FFCA28;
	}
	.color-yanzhong{
		color: #D9001B;
	}
	.bg-active{
		width: 88%;
		margin-left: 0;
		border-bottom: 2px solid #82B2FF;
	}
	.search-view{
		position: relative;
	}
	.search-re-view{
		position: absolute;
		top: 100%;
		left: 0;
		right: 0;
		min-height: 200rpx;
		background-color: #ffffff;
		overflow-y: auto;
		z-index: 55;
	}
	.mingc-inp{
		background-color: #ffffff;
	}
	.si-view-item{
		overflow: visible;
	}
	.names-item{
		font-size: 30rpx;
		padding-left: 20rpx;
		padding-bottom: 10rpx;
		line-height: 40rpx;
		
	}
	.noyouer-view{
		text-align: center;
		color: $uni-border-color;
	}
</style>